<?php
require_once 'script.php';
include("Hierarchy.php");
include("File.php");
if($_GET['actiune'] === "mutare"){
            $file = File::findById($_GET['file']);  // we get file info
            $file->copy($_GET['DestinationFolder'], $_GET['hierarchy']);
            File::deleteAll($_GET['file']); // we delete all files info, we can do this because differently from hierarchy they are not linked
            header('Location: index.php?hierarchy='.$_GET['hierarchy']);
}
?>
<form name='form1' enctype='multipart/form-data' method='get' action='move.php'>
        Folder: 
        <select name="DestinationFolder">
            <?php
                $file = File::findById($_GET['id']);
                $possibleFolders = $file->getAllPossibleFolders();
                foreach ($possibleFolders as $folder){
                    $hierarchy = Hierarchy::findById($folder->HierarchyId);
                    $parents = explode(',', $hierarchy->IdHash);
                    $path = '';
                    foreach ($parents as $parent){
                        $parentFile = File::findByHierarchy($parent);
                        $path .= $parentFile->Name . "/";
                    }
                    echo "<option value = " . $folder->Id . ">" . $path . "</option>";
                }
            ?>
        </select>
        <br/>
        Name:
        <?php
            echo "<input id='Name' type='text' name='Name' value='" . $file->Name . "'>"
        ?>
        <br/>
        <input name='actiune' type='hidden' value='mutare'>
        <?php
        echo "<input name='hierarchy' type='hidden' value='" . $_GET['hierarchy'] . "'>";
        echo "<input name='file' type='hidden' value='" . $file->Id . "'>";
        ?>
        <br/>
        <input type='submit' value='Muta' name='Submit' role='button' aria-disabled='false'>
        <?php
            echo "<INPUT TYPE=BUTTON VALUE='&Icirc;napoi' CLASS=b ONCLICK='window.location=\"index.php?hierarchy=" . $_GET['hierarchy'] . "\";'>";
        ?>
</form>